#include <stdlib.h>
#include <stdio.h>
#include <sqlite3.h>

int main(){
  sqlite3 *db;
  char *sql;
  char *errmsg;
  //如果数据库不存在，就会创建在同一个目录下
  int res = sqlite3_open ("/home/wan/mydb",&db);
  if(res){
    fprintf (stderr, "打开数据库错误：%s\n",sqlite3_errmsg(db));
    exit (0);
  }
  /* sql = "insert into student(name)"\ */
  /*       "values('小红')"; */
  sql = "insert into emp(name,birthday)"\
        "values('小王','2012-12-12')";
  res = sqlite3_exec (db, sql, NULL, 0, &errmsg);
  if(res!=SQLITE_OK){
    fprintf(stderr,"增加数据有误:%s\n",errmsg);
    sqlite3_free (errmsg);
  }else{
    printf("新增成功\n");
  }
  sqlite3_close (db);
  return 0;
}
